package;

import nme.display.MovieClip;
import nme.display.SimpleButton;
import nme.events.MouseEvent;
import nme.display.Bitmap;

/**
 * @author jonathanmoriarty
 */
class CreditsScreen extends MovieClip, implements Screen
{
	// TODO: Add an animated background.
	private var _background:Bitmap;
	
	private var _menuButton:SimpleButton;
	inline private static var MENU_BUTTON_X:Int = 400;
	inline private static var MENU_BUTTON_Y:Int = 200;
	
	public function new() 
	{
		super();
		
		_background = Tools.loadBitmap( "credits_screen" );
		_background.x = 0;
		_background.y = 0;
		addChild(_background);
		
		_makeMenuButton();
		show();
	}
	
	private function _makeMenuButton():Void
	{
		_menuButton = new SimpleButton();
		_menuButton.upState = Tools.loadBitmap( "menu_button_up" );
		_menuButton.overState = Tools.loadBitmap( "menu_button_up" );
		_menuButton.downState = Tools.loadBitmap( "menu_button_down" );
		_menuButton.hitTestState = _menuButton.overState;
		_menuButton.x = MENU_BUTTON_X;
		_menuButton.y = MENU_BUTTON_Y;
		addChild( _menuButton );
	}
	
	public function _onClickMenu( l_event:MouseEvent ):Void
	{
		dispatchEvent( new NavigationEvent( NavigationEvent.MENU ) );
	}
	
	public function show():Void
	{
		this.visible = true;
		_menuButton.addEventListener( MouseEvent.CLICK, _onClickMenu );
	}
	
	public function hide():Void
	{
		this.visible = false;
		if ( _menuButton.hasEventListener( MouseEvent.CLICK ) )
		{
			_menuButton.removeEventListener( MouseEvent.CLICK, _onClickMenu );
		}
	}
	
	public function reset():Void
	{
		// nothing needed here at the moment.
	}
	
	public function destroy():Void
	{
		hide();
		removeChild( _menuButton );
		_menuButton = null;
	}

}